package com.zlyx.easy.weblog.filter;

import org.slf4j.MDC;

import com.zlyx.easy.core.utils.ThreadUtils;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

public class LogEventFilter extends Filter<ILoggingEvent> {

	@Override
	public FilterReply decide(ILoggingEvent event) {
		try {
			if (!event.getMDCPropertyMap().containsKey("traceId")) {
				MDC.put("traceId", ThreadUtils.getName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return FilterReply.ACCEPT;
	}
}